/**
 * Copyright (c) 2020 kedacom
 * OpenATC is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 * http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 **/
<template>
  <el-select
    v-model="value"
    :multiple="multiple"
    :disabled="disabled"
    :size="size"
    collapse-tags
    clearable
    filterable
    :placeholder="$t('openatc.common.placeholder')"
    @change="onChange"
  >
    <el-option
      v-for="(item, index) in options"
      :key="index"
      :label="item.label"
      :value="item.value"
    >
    </el-option>
  </el-select>
</template>
<script>
export default {
  name: 'SelectControl',
  props: {
    agentid: {
      type: String,
      required: false
    },
    multiple: {
      type: Boolean,
      default: false
    },
    disabled: {
      type: Boolean,
      default: false
    },
    size: {
      type: String,
      default: 'small'
    },
    defaultValue: {
      type: Number,
      default: 0
    }
  },
  data () {
    return {
      value: [],
      options: [
        {
          value: -1,
          label: this.$t('openatc.dutyroute.unknowControl')
        },
        {
          value: 0,
          label: this.$t('openatccomponents.overview.modelList0')
        },
        {
          value: 1,
          label: this.$t('openatccomponents.overview.modelList1')
        },
        {
          value: 2,
          label: this.$t('openatccomponents.overview.modelList2')
        },
        {
          value: 3,
          label: this.$t('openatccomponents.overview.modelList3')
        },
        {
          value: 4,
          label: this.$t('openatccomponents.overview.modelList4')
        },
        {
          value: 5,
          label: this.$t('openatccomponents.overview.modelList5')
        },
        {
          value: 6,
          label: this.$t('openatccomponents.overview.modelList6')
        },
        {
          value: 7,
          label: this.$t('openatccomponents.overview.modelList7')
        },
        {
          value: 8,
          label: this.$t('openatccomponents.overview.modelList8')
        },
        {
          value: 9,
          label: this.$t('openatccomponents.overview.modelList9')
        },
        {
          value: 10,
          label: this.$t('openatccomponents.overview.modelList10')
        },
        {
          value: 11,
          label: this.$t('openatccomponents.overview.modelList11')
        },
        {
          value: 12,
          label: this.$t('openatccomponents.overview.modelList12')
        },
        {
          value: 13,
          label: this.$t('openatccomponents.overview.modelList13')
        },
        {
          value: 14,
          label: this.$t('openatccomponents.overview.modelList14')
        },
        {
          value: 15,
          label: this.$t('openatccomponents.overview.modelList15')
        },
        {
          value: 16,
          label: this.$t('openatccomponents.overview.modelList16')
        },
        {
          value: 17,
          label: this.$t('openatccomponents.overview.modelList17')
        },
        {
          value: 18,
          label: this.$t('openatccomponents.overview.modelList18')
        },
        {
          value: 19,
          label: this.$t('openatccomponents.overview.modelList19')
        },
        {
          value: 21,
          label: this.$t('openatccomponents.overview.modelList21')
        },
        {
          value: 22,
          label: this.$t('openatccomponents.overview.modelList22')
        },
        {
          value: 23,
          label: this.$t('openatccomponents.overview.modelList23')
        },
        {
          value: 24,
          label: this.$t('openatccomponents.overview.modelList24')
        },
        {
          value: 99,
          label: this.$t('openatccomponents.overview.modelList99')
        },
        {
          value: 100,
          label: this.$t('openatccomponents.overview.modelList100')
        }
      ]
    }
  },
  created () {
    if (this.defaultValue) {
      this.value = this.defaultValue
    }
  },
  methods: {
    onLoad () {
    },
    onChange (val) {
      this.$emit('onChange', val, this.agentid)
    },
    init (val) {
      let target = val
      if (this.multiple) {
        target = [val]
      }
      this.value = target
    },
    getNameById (id) {
      let res = ''
      for (const item of this.options) {
        if (id === item.value) {
          res = item.label
          break
        }
      }
      return res
    }
  }
}
</script>
